<?php
namespace app\mxty\model;

use think\model\Pivot;

class ArenaPartTimeFragment extends Pivot
{
    protected $table = 'athlon_arena_part_time_fragment';

    public function fragment()
    {
        return $this->belongsTo(TimeFragment::class);
    }

    public function part()
    {
        return $this->belongsTo(ArenaPart::class);
    }

    // 关联该场次对应的所有预订记录
    public function bookings()
    {
        return $this->hasMany(BookingFragment::class, 'part_time_fragment_id');
    }

    public function getArenaAndPartStatus($id) {
        $session = self::with(['part', 'part.arena'])->find($id);
        if($session->isEmpty()) {
            throwError('没有该场次信息');
        }

        return [
            $session->part->status,
            $session->part->arena->status
        ];
    }

    public function getInfo($ids)
    {
        return self::with(['fragment', 'part', 'part.arena'])->select($ids);
    }
}
